<?php 
	$atsi_id = 0;

	//for form submit
	if($_SERVER['REQUEST_METHOD'] == "POST"){
		if(isset($_POST['id']) && !empty($_POST['id'])){
			$table_def 	= array(
							'update' => $_POST,
							'filter' => 'id = '.$_POST['id']
						  );
			$atsi 		= new Atsi($table_def);
			$atsi->Update();
			$message = 2;
		}else{
			$_POST['date_created'] = date("Y-m-d h:i:s");
			$table_def 	= array('add' => $_POST);
			$atsi 		= new Atsi($table_def);
			$atsi->Insert();
			$message = 1;
		}
	}

	//for edit form - fetch data
	if($_SERVER['REQUEST_METHOD'] == "GET"){
		$message = 0;
		if(isset($_GET['id']) && !empty($_GET['id'])){
			$atsi_id = $_GET['id'];

			$params = array( 'filter' => 'id = '.$atsi_id);
			$atsi 	= new Atsi($params);
			$row 	= $atsi->Select();
		}
	}
?>